﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Data;

namespace ZG_member.DAL
{
    public class WorkerWasteBook
    {
        //添加数据
        public bool add(ZG_member.Model.WorkerWasteBook model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into WorkerWasteBook(");
            strSql.Append("WorkerId,Dates,money,memberId)");
            strSql.Append("values (");
            strSql.Append("@WorkerId,@Dates,@money,@memberId)");
            SqlParameter[] parameters = {
					 
					new SqlParameter("@WorkerId", SqlDbType.VarChar,50),
					new SqlParameter("@Dates", SqlDbType.DateTime),
					new SqlParameter("@money", SqlDbType.Money,200),
                    new SqlParameter("@memberId", SqlDbType.VarChar,50)};

            parameters[0].Value = model.WorkerId;
            parameters[1].Value = model.Dates;
            parameters[2].Value = model.money;
            parameters[3].Value = model.memberId;


            object obj = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (obj == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public DataSet GetListWhere(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM WorkerWasteBook");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ZG_member.Model.WorkerWasteBook model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update WorkerWasteBook set ");
            strSql.Append("WorkerId=@WorkerId,");
            strSql.Append("Dates=@Dates,");
            strSql.Append("money=@money,");
            strSql.Append("memberId=@memberId");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@WorkerId", SqlDbType.VarChar,50),
					new SqlParameter("@Dates", SqlDbType.DateTime),
					new SqlParameter("@money", SqlDbType.Money,200),
                    new SqlParameter("@memberId", SqlDbType.VarChar,50),
					new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = model.WorkerId;
            parameters[1].Value = model.Dates;
            parameters[2].Value = model.money;
            parameters[3].Value = model.memberId;
            parameters[4].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return DbHelperSQL.Query(strWhere.ToString());
        }
    }
}
